package br.com.fafica.sisape.view;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.Color;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.SwingConstants;
import javax.swing.JTextField;
import javax.swing.JButton;

import br.com.fafica.sisape.control.ControllerMedico;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class TelaMedicoCadastra extends JFrame {

	private JPanel contentPane;
	private JTextField campoNome;
	private JTextField campoCrm;
	private JTextField campoTelefone;
	private JTextField campoUsuario;
	private JTextField campoSenha;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					TelaMedicoCadastra frame = new TelaMedicoCadastra();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public TelaMedicoCadastra() {
		setResizable(false);
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 458, 254);
		contentPane = new JPanel();
		contentPane.setBackground(new Color(255, 255, 255));
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblNome = new JLabel("Nome:");
		lblNome.setHorizontalAlignment(SwingConstants.RIGHT);
		lblNome.setForeground(new Color(0, 0, 128));
		lblNome.setFont(new Font("Tahoma", Font.PLAIN, 12));
		lblNome.setBounds(50, 33, 46, 14);
		contentPane.add(lblNome);
		
		campoNome = new JTextField();
		campoNome.setForeground(new Color(0, 0, 128));
		campoNome.setFont(new Font("Tahoma", Font.PLAIN, 12));
		campoNome.setBounds(100, 30, 270, 21);
		contentPane.add(campoNome);
		campoNome.setColumns(10);
		
		JLabel lblCrm = new JLabel("CRM:");
		lblCrm.setHorizontalAlignment(SwingConstants.RIGHT);
		lblCrm.setForeground(new Color(0, 0, 128));
		lblCrm.setFont(new Font("Tahoma", Font.PLAIN, 12));
		lblCrm.setBounds(50, 65, 46, 14);
		contentPane.add(lblCrm);
		
		campoCrm = new JTextField();
		campoCrm.setForeground(new Color(0, 0, 128));
		campoCrm.setFont(new Font("Tahoma", Font.PLAIN, 12));
		campoCrm.setColumns(10);
		campoCrm.setBounds(100, 62, 270, 21);
		contentPane.add(campoCrm);
		
		JLabel lblTelefone = new JLabel("Telefone:");
		lblTelefone.setHorizontalAlignment(SwingConstants.RIGHT);
		lblTelefone.setForeground(new Color(0, 0, 128));
		lblTelefone.setFont(new Font("Tahoma", Font.PLAIN, 12));
		lblTelefone.setBounds(30, 97, 66, 14);
		contentPane.add(lblTelefone);
		
		campoTelefone = new JTextField();
		campoTelefone.setForeground(new Color(0, 0, 128));
		campoTelefone.setFont(new Font("Tahoma", Font.PLAIN, 12));
		campoTelefone.setColumns(10);
		campoTelefone.setBounds(100, 94, 135, 21);
		contentPane.add(campoTelefone);
		
		JLabel lblUsurio = new JLabel("Usu\u00E1rio:");
		lblUsurio.setHorizontalAlignment(SwingConstants.RIGHT);
		lblUsurio.setForeground(new Color(0, 0, 128));
		lblUsurio.setFont(new Font("Tahoma", Font.PLAIN, 12));
		lblUsurio.setBounds(30, 132, 66, 14);
		contentPane.add(lblUsurio);
		
		campoUsuario = new JTextField();
		campoUsuario.setForeground(new Color(0, 0, 128));
		campoUsuario.setFont(new Font("Tahoma", Font.PLAIN, 12));
		campoUsuario.setColumns(10);
		campoUsuario.setBounds(100, 129, 135, 21);
		contentPane.add(campoUsuario);
		
		JLabel lblSenha = new JLabel("Senha:");
		lblSenha.setHorizontalAlignment(SwingConstants.RIGHT);
		lblSenha.setForeground(new Color(0, 0, 128));
		lblSenha.setFont(new Font("Tahoma", Font.PLAIN, 12));
		lblSenha.setBounds(30, 164, 66, 14);
		contentPane.add(lblSenha);
		
		campoSenha = new JTextField();
		campoSenha.setForeground(new Color(0, 0, 128));
		campoSenha.setFont(new Font("Tahoma", Font.PLAIN, 12));
		campoSenha.setColumns(10);
		campoSenha.setBounds(100, 161, 135, 21);
		contentPane.add(campoSenha);
		
		JButton btnSalvar = new JButton("Salvar");
		btnSalvar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String nome = campoNome.getText();
				String crm = campoCrm.getText();
				String telefone = campoTelefone.getText();
				String usuario = campoUsuario.getText();
				String senha = campoSenha.getText();
				
				ControllerMedico control = new ControllerMedico();
				control.InserirMedico(nome, telefone, crm, usuario, senha);
				dispose();
			}
		});
		btnSalvar.setForeground(new Color(0, 0, 128));
		btnSalvar.setFont(new Font("Tahoma", Font.PLAIN, 12));
		btnSalvar.setBounds(328, 156, 89, 31);
		contentPane.add(btnSalvar);
	}

}
